var o_map_extend=crossApi={
	global_cfg:{actionSet:'',callback:'',url:'',ref:'',_actionSet:'',_callback:''},
	localRef:{domain:document.domain,cbPath:'/o_cn/',cbPage:['action.htm','action.jsp'],cbType:0,ref:''},
	localRefState:{},
	remoteRef:{domain:'',cbPath:'/extend/',cbPage:['action.htm','action.jsp'],cbType:0,ref:''},
	remoteRefSate:{},
	remoteRefSave:{},
	remoteIfr:{},
	main:null,
	domain:null,
	isInit:false,
	debug:false,
	init:function(){
		var code=0;
		this.createIfr();
		if(typeof(this.initEx)=='function'){
			if(!this.initEx()) code='0x1002';
		}
		if(code==0) this.isInit=true;
		else this.log(code,true);
	},
	log:function(code,flag){
		if(flag||this.debug) alert(code);
	},
	extend:function(src,rep){
		for(var item in src){
			if(!rep&&this[item]!=null) continue;
			this[item]=src[item];
		}
	},
	setTimeout:function(fun, delay) { 
		var obj=this;
		if(typeof fun == 'function'){  
			var argu = Array.prototype.slice.call(arguments,2);  
			var f = (function(){ fun.apply(obj, argu); });  
			return window.setTimeout(f, delay); 
		}
		return window.setTimeout(fun,delay);
	},
	
	setLocalRef:function(obj){
		var ref=this.createRef(obj);
		if(ref.domain){
			this.localRef=ref;
			this.localRefState={};
		}
	},
	getLocalRef:function(){
		return this.localRef;
	},
	setRemoteRef:function(obj){
		var ref=this.createRef(obj);
		if(ref.domain){
			this.remoteRef=ref;
			this.remoteRefState={};
			this.remoteRefSave[ref.domain]=ref;
		}
	},
	getRemoteRef:function(){
		return this.remoteRef;
	},
	setLocalRefState:function(domain,value){
		this.localRefState[domain]=value;
	},
	getLocalRefState:function(domain){
		return this.localRefState[domain];
	},
	createRef:function(obj){
		var ref={domain:'',cbPath:'/extend/',cbPage:['action.htm','action.jsp'],cbType:0,ref:''};
		if(typeof(obj)=='string'){
			ref=this.str2ref(obj);
		}
		else if(typeof(obj)=='object'){
			ref=obj;
		}
		return ref;
	},
	str2ref:function(str){
		var arr=str.split(';');
		if(arr.length<5){
			alert('err');
			return false;
		}
		var ref={};
		ref.domain=arr[0];
		ref.cbPath=arr[1];
		ref.cbPage=arr[2].split(',');
		ref.cbType=arr[3];
		ref.ref=arr[4];
		return ref;
	},
	ref2str:function(ref){
		var str='';
		str=ref.domain+';'+ref.cbPath+';'+ref.cbPage.join(',')+';'+ref.cbType+';'+ref.ref;
		return str;
	},
	choiceRemoteRef:function(domain){
		if(this.remoteRefSave[domain]){
			this.setRemoteRef(this.remoteRefSave[domain]);
		}
		else{
			var ref=this.createRef();
			ref.domain=domain;
			this.setRemoteRef(ref);
		}
	},
	getCbUrl:function(domain){
		var remoteRef=null;
		if(domain&&this.remoteRefSave[domain]){
			remoteRef=this.remoteRefSave[domain];
		}
		else{
			remoteRef=this.remoteRef;
		}
		return remoteRef.domain+remoteRef.cbPath+remoteRef.cbPage[0];
	},
	findTarget:function(ref){
		var p=parent;
		if(ref){
			var arr=ref.split('.');
			for(var i=0;i<arr.length;i++){
				if(p){
					p=p[arr[i]];
				}
				else{
					return null;
				}
			}
		}
		return p;
	},
	setLocalIfr:function(ifr){//
		this.lref=ifr;
	},
	getRemoteIfr:function(ifr){
		if(ifr){
			if(this.remoteIfr[ifr]){
				if(!this.remoteIfr[ifr].obj)this.remoteIfr[ifr].obj=this.findTarget(ifr);
				return this.remoteIfr[ifr];
			}
			else{
				alert('target err');
				return {};
			}
		}
		else{
			var obj=this.main;
			var domain=this.getRemoteRef().domain;
			return {obj:obj,domain:domain};
		}
	},
	putRemoteIfr:function(domain,ifr){//
		var obj=this.findTarget(ifr);
		var win={obj:obj,domain:domain};
		if(!this.remoteRefSave[domain]){
			this.choiceRemoteRef(domain);
		}
		this.main=win.obj;
		this.remoteIfr[ifr]=win;
	},
	getAllCfg:function(){
		return this.global_cfg;
	},
	setAllCfg:function(params){
		if(params['url']) this.setUrl(params['url']);
		if(params['actionSet']) this.global_cfg['actionSet']=params['actionSet'];
		if(params['callback']) this.global_cfg['callback']=params['callback'];
		if(params['ref']) this.global_cfg['ref']=params['ref'];
	},
	setUrl:function(url){
		var re=/^(\w+\.)+\w+$/;
		if(re.test(url)){
			this.global_cfg['url']='http://'+url+'/o_cn/action.htm';
		}
		else{
			this.global_cfg['url']=url;
		}
	},
	setState1:function(params){
		this.setAllCfg(params);
		if(params['save']){
			if(params['actionSet']) this.global_cfg['_actionSet']=params['actionSet'];
			if(params['callback']) this.global_cfg['_callback']=params['callback'];
		}
	},
	setCfg:function(name,value){
		this.global_cfg[name]=value;
	},
	getCfg:function(name){
		return this.global_cfg[name];
	},
	setActionSet:function(value){
		this.global_cfg['actionSet']=value;
	},
	getAcionSet:function(){
		return this.global_cfg['actionSet'];
	},
	params2str:function(params){
		var str='';
		for(var item in params){
			str+=item+'='+encodeURIComponent(params[item])+'&';
		}
		if(str.length==0) return str;
		else{
			str='?'+str;
			return str.substr(0,str.length-1);
		}
	},
	encodeStr:function(str){
		var toCodeTable={'%':'__9999__','?':1,'=':2,'&':3,'/':4,'\\':5};
		var result='';
		for(var i=0;i<str.length;i++){
			var c=str.charAt(i);
			if(toCodeTable[c]) c='%'+toCodeTable[c];
			result+=c;
		}
		return result;
	},
	decodeStr:function(str){
		var fromCodeTable={1:'?',2:'=',3:'&',4:'/',5:'\\'};		
		var re=/%(\d)/g;
		var result=str.replace(re,function(mstr,m1){
			if(fromCodeTable[m1]) return fromCodeTable[m1];
			else return '';
		});
		result=result.replace(/%__9999__/g,'%');
		return result;
	},
	execute:function(params){
		var remoteRef=this.remoteRef;
		if(!this.getLocalRefState(remoteRef.domain)){
			params.localRef=this.ref2str(this.localRef);
			//this.setLocalRefState(remoteRef.domain,{});
		}
		if(!params.remote){
			if(!params['action']&&this.global_cfg['callback']){//
				params['action']=this.global_cfg['callback'];
			}
			params.lref=this.lref;
			params['ref']=this.global_cfg['ref'];
			if(params['ifr'])params['ref']=params['ifr'];
			var remoteIfr=this.getRemoteIfr(params['ifr']);
			var domain=remoteIfr.domain;
			jsaction.location='http://'+this.getCbUrl(domain)+this.params2str(params);
			this.cleanCallBack();
		}
		else{
			this.executeRemote(params);
		}
	},
	executeRemote:function(params,times){
		if(!this.main) return;
		if(!times)times=0;
		times++;
		if(times>20){
			alert(params.action+'超时');
			return;
		}
		if(!this.main.jsaction){
			this.setTimeout(this.executeRemote,500,params,times);
			return false;
		}
		var remoteRef=this.remoteRef;
		params.lref=this.lref;
		var target=null;//
		var domain=null;
		if(params.ifr){
			if(this.remoteIfr[params.ifr]){
				target=this.remoteIfr[params.ifr].obj;
				domain=this.remoteIfr[params.ifr].domain;
			}
			else{
				alert('target');
				return;
			}
		}
		else{
			target=this.main;
		}
		target.jsaction.location='http://'+this.getCbUrl(domain)+this.params2str(params);
	},
	cleanCallBack:function(){
		this.global_cfg['callback']=this.global_cfg['_callback'];
	},
	cleanActionSet:function(){
		this.global_cfg['actionSet']=this.global_cfg['_actionSet'];
	},
	createIfr:function(flag){
		var obj=document.getElementById('jsaction');
		if(obj) return;
		if(document.body){
			var htmlStr='<iframe id="jsaction" name="jsaction" src="" style="display:none"></iframe>';
			var div=document.createElement('div');
			div.style.display='none';
			div.innerHTML=htmlStr;
			if(flag)document.body.appendChild(div);
			else document.write(htmlStr);
		}
		else{
			setTimeout(this.createIfr,500);
		}
	},
	listener:function(){
		return false;
	},
	setListener:function(listener){
		this.listener=listener;
	},
	getListener:function(){
		return this.listener;
	}
};
o_map_extend.extend({
	initEx:function(){
		//this.domain='gz.o.cn';
		this.setDomain('gz.o.cn');
		return true;
	},
	setDomain:function(domain){
		if(!domain) return;
		this.domain=domain;
		this.choiceRemoteRef(domain);
	},
	createMap:function(id,w,h,domain,params){
		if(!document.body){
			alert('地图创建位置错误');
			return false;
		}
		if(!id) id='map';
		if(document.getElementById(id)){
			alert('ID重复');
			return false;
		}
		this.init();
		if(!domain) domain='gz.o.cn';
		this.setDomain(domain);
		var miniF=0,x='',y='',popstr='';
		if(params){
			x=typeof(params.x)=='number'?params.x:'';
			y=typeof(params.y)=='number'?params.y:'';
			popstr=typeof(params.popstr)=='string'?params.popstr:'';
			miniF=params.miniMapView?1:0;
		}
		if((!params||!params.miniMapView)&&w>=400&h>=300) miniF=1;
		var url='http://'+this.domain+'/map.jsp?w='+w+'&h='+h+'&x='+x+'&y='+y+'&m='+miniF+'&b=1&search=1&ui='+document.domain+'&popstr='+encodeURIComponent(popstr);
		var str='<iframe id="'+id+'" name="'+id+'" scrolling="no" frameborder="0" width="'+w+'" height="'+h+'" src="'+url+'"></iframe>';
		var __m=null;
		if(!params||!params.open){
			document.write(str);
			__m=eval(id);
		}
		else{
			__m=this.openwin(url,id,w,h);
		}
		this.setCfg('cfg',id);
		this.setConfig(__m);
		return map;
	},
	openwin:function(url,title,width,height,left,top){
		if(!url) return false;
		if(!width) width=200;
		if(!height) height=200;
		if(!left) left=0;
		if(!top) top=0;
		return window.open(url,title,'menubar=no,toolbar=no,location=no,scrollbar=no,resizale=no,directories=no,width='+width+',height='+height+',top='+top+',left='+left);
	},
	setConfig:function(m,ref){
		if(!ref) ref='';
		if(m){
			this.main=m;
		}
		else if(typeof(crossIfr)=='object'&&crossIfr.jsaction){
			this.map=map;
		}
		else return false;
		if(this.main.opener){
			if(ref) ref='opener.'+ref;
			else ref='opener';
		}
		this.setLocalIfr(ref);
		return true;
	},
	test:function(){
		this.execute({action:'test',remote:true});
	},
	go2xy:function(x,y){
		this.execute({action:'go2xy',x:x,y:y,remote:true});
	},
	go2xyS:function(x,y){
		this.execute({action:'go2xyS',x:x,y:y,remote:true});
	},
	createSimpleLabel:function(id,x,y,content){
		this.execute({action:'createSimpleLabel',id:id,x:x,y:y,content:content,remote:true});
	},
	getPosXYOpen:function(callback){
		this.execute({action:'getPosXYOpen',callback:callback,remote:true});
	},
	setState:function(params){
		params.action='setState1';
		params.remote=true;
		this.execute(params);
	},
	getMapConfig:function(callback){
		this.execute({action:'getMapConfig',callback:callback,remote:true});
	},
	destory:function(){
		if(this.main.opener){
			this.execute({action:'closeWin',remote:true});
		}
	}
});